package com.xyht.medicine_management_system.modules.common.controller;


import com.xyht.medicine_management_system.common.annotation.RepeatRequestCheck;
import com.xyht.medicine_management_system.common.commonReturn.ResponseResult;
import com.xyht.medicine_management_system.modules.common.service.MmsFileUpDownService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 * 文件上传下载
 * </p>
 *
 * @author XYHT
 * @since 2022-11-29
 */
@RestController
@RequestMapping("/file")
@Log4j2
public class MmsFileUpDownController {
    @Autowired
    private MmsFileUpDownService mmsFileUpDownService;

    @PostMapping("/upload")
    @RepeatRequestCheck(name = "fileUpload")
    public ResponseResult fileUpload(@RequestParam("file") MultipartFile file) {
        return mmsFileUpDownService.fileUpload(file);
    }

    @GetMapping("/download")
    public ResponseResult fileDownload(@RequestParam("fileName") String fileName, HttpServletResponse response) {
        return mmsFileUpDownService.fileDownload(fileName, response);
    }

    @GetMapping("/moduleDownload")
    public ResponseResult moduleDownload(@RequestParam("fileName") String fileName, HttpServletResponse response) {
        return mmsFileUpDownService.moduleDownload(fileName, response);
    }

}

